package com.hyt.it.ogt.ksmonitor.statistics.executor;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 朱振宇
 * @since 2022-11-24
 */
@Component
public class StatisticsExecutorFactory implements InitializingBean {

    private static ThreadPoolExecutor executor;

    @Override
    public void afterPropertiesSet() {
        int nThreads = Runtime.getRuntime().availableProcessors();
        executor = new ThreadPoolExecutor(nThreads, nThreads, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(500));
    }

    public static final ThreadPoolExecutor getThreadPoolExecutor() {
        return executor;
    }
}
